#! /bin/bash

dev_and_ip=$(ip -o -4 addr show | awk '{print $2" "$4}')

# echo $dev_and_ip

di_arr=(${dev_and_ip})

echo 0 > "/proc/sys/net/ipv4/conf/all/rp_filter"

for ((i=0;i<${#di_arr[@]};i=i+2))
do
	ip=(${di_arr[i+1]//./ })
	# echo ${di_arr[i]} ${ip[@]}
	echo 0 > "/proc/sys/net/ipv4/conf/${di_arr[i]}/rp_filter"
	if [[ ${di_arr[i]} == lo* ]]; then
		continue
	fi
	if [[ ${di_arr[i]} == ppp* ]]; then
		route add default ${di_arr[i]} &>/dev/null
		continue
	fi
	route add default gw "${ip[0]}.${ip[1]}.${ip[2]}.1" ${di_arr[i]} &>/dev/null
done

../bin/dev_name rndis
